<?php

class Edit implements Action {

    private $client_id;
    private $name;
    private $bday;
    private $address;
    private $cellPhone;
    private $eMail;

    public function setParams($id = "") {
        $this->client_id = $id;
        $this->name = $_POST['name'];
        $this->bday = $_POST['birthdate'];
        $this->address = $_POST['address'];
        $this->cellPhone = $_POST['cellPhone'];
        $this->eMail = $_POST['eMail'];
    }

    public function validate($response) {
        if ($this->client_id == "") {
            $response->addError("ID not specified");
        }
        if ($this->name == "") {
            $response->addError("Name missing");
        }
    }

    public function execute($response) {
        $con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(mysql_error());
        mysql_select_db(DB_NAME, $con) or die(mysql_error());
        $sql = "UPDATE clients 
                SET name = '$this->name',
                    bday = '$this->bday', 
                    address = '$this->address', 
                    cellPhone = '$this->cellPhone', 
                    eMail ='$this->eMail'
                WHERE client_id='$this->client_id'";
        mysql_query($sql, $con) or die(mysql_error());
    }

    public function getContentType() {
        return JSON;
    }

    public function getHTTPMethod() {
        return POST;
    }

}

?>
